import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:riverpod_t/config/response_model.dart';
import 'package:riverpod_t/page/home/data/model/cartoon_recommend_entity.dart';
import 'package:riverpod_t/page/home/data/model/cartoon_series_entity.dart';
import 'package:riverpod_t/page/home/data/model/detail_model_entity.dart';
import 'package:riverpod_t/page/home/data/repository/home_repository.dart';
import '../state/home_detail_state.dart';
part 'home_detail_river.g.dart';

@riverpod
class HomeDetailRiver extends _$HomeDetailRiver {
  @override
  Future<HomeDetailState> build() async {
    DetailModelData detailModelData = await getMainData();
    List<CartoonSeriesDataSeriesComics>? seriesList = await getSeriesData();
    List<CartoonRecommendDataInfos>? recommendList = await getRecommendData();
    return HomeDetailState(
      modelData: detailModelData,
      recommends: recommendList,
      seriesComics: seriesList,
    );
  }

  /// 请求主数据
  Future<DetailModelData> getMainData() async {
    ResponseModel responseModel = await HomeRepository.getMainData<DetailModelData>();
    return responseModel.data;
  }

  /// 请求系列数据
  Future<List<CartoonSeriesDataSeriesComics>?> getSeriesData() async {
    ResponseModel responseModel = await HomeRepository.getSeriesData<CartoonSeriesData>();
    CartoonSeriesData? cartoonSeriesData = responseModel.data;
    return cartoonSeriesData?.seriesComics;
  }

  /// 请求推荐数据
  Future<List<CartoonRecommendDataInfos>?> getRecommendData() async {
    ResponseModel responseModel = await HomeRepository.getRecommendData<CartoonRecommendData>();
    CartoonRecommendData? cartoonRecommendData = responseModel.data;
    return cartoonRecommendData?.infos;
  }
}
